package com.learning.intercepter;

import org.apache.ibatis.executor.parameter.ParameterHandler;
import org.apache.ibatis.plugin.Interceptor;
import org.apache.ibatis.plugin.Intercepts;
import org.apache.ibatis.plugin.Invocation;
import org.apache.ibatis.plugin.Signature;

import java.sql.PreparedStatement;

/**
 * @author jukg
 * @date 2025/01/07 15:15
 * @description
 */
@Intercepts(@Signature(type = ParameterHandler.class, method = "setParameters", args = PreparedStatement.class))
public class ParameterIntercepter implements Interceptor {
    @Override
    public Object intercept(Invocation invocation) throws Throwable {
        // 获取参数处理器实例
        ParameterHandler parameterHandler = (ParameterHandler) invocation.getTarget();
        // 获取参数对象
        Object parameters = parameterHandler.getParameterObject();
        // 加密
        desensitization(parameters);
        // 执行原始方法
        invocation.proceed();
        return null;
    }

    public void desensitization(Object parameters) {

    }
}
